home *** CD-ROM | disk | FTP | other *** search
Wrap
class Engine extends MovieClip { var blocker; var lvl; var allKids; var indQueue; var perfCont; var newKidFrequency; var shownTiredTip; var shownExhaustedTip; var volumePumped; var enteringLabourPool1; var pumpsHolder; var goingToPump; var leavingGame1; var leavingGame2; var labourPoolQueuePath; var pumps; var pumpPaths; var pumpQueues; var pumpExits; var labourPool; var f; var onEnterFrame; var hud; var messages; var timeRemaining = 0; var _paused = false; static var INIT_NEW_KID_FREQUENCY = 2; static var NEW_KID_FREQUENCY_INCREASE = 0.16; static var MAX_LABOUR_POOL_SIZE = 5; static var FPS = 30; static var NUM_LVLS = 8; static var LVL_TARGS = [3,5,9,14,22.5,30,38.5,50]; static var LVL_TIMES = [60,35,35,35,35,35,35,35]; static var TIPS = ["Welcome to the Play Pump Game! You must pump water as fast as possible! To get started, click on the pump","As more kids arrive, you can send them to the pump too - the more kids the faster you pump water","Be careful, as the longer the kids play, the more tired they get - and tired kids will slow you down","One of the children is getting tired! Click the child to give them a break before they get so tired they slow the other kids down!","Oh no! One of the kids is exhausted, and slowing the other kids down! Click on them to let them rest!"]; static var LEVEL_START_TIPS = ["Well done! Now you have two pumps to control, and some extra time. Click on the other pump to get kids to play on that!","Excellent! Another pump and more time!","Wow! Another pump! Have you noticed that the rate you get kids has increased?","Another pump! Spread the kids out on the pumps to spread the fun and pump more water!","Great work - keep it up!","Well Done! Now you have even more pumps","This is it - fill the bar up once more and you win!"]; static var TIP_LOW_TIME = "Oh no! You\'re running out of time!"; static var SHOW_FIRST_TIP_AT = 30; static var SHOW_LOW_TIME_AT = 20 * Engine.FPS; static var MC_TIMEUP_EVENTS = [1264,1265,1266,1267,1268,1269,1270,1271]; static var MC_GAME_STARTED = 1263; static var MC_GAME_COMPLETE = 1272; function Engine() { super(); this.blocker._visible = false; } function startGame() { var _loc3_ = undefined; this.lvl = 0; this.allKids = []; this.indQueue = []; this.perfCont = new PerformanceController(); this.newKidFrequency = Engine.INIT_NEW_KID_FREQUENCY; this.shownTiredTip = false; this.shownExhaustedTip = false; _loc3_ = 0; while(_loc3_ < GameObject.MAX_ITEMS) { this.indQueue[_loc3_] = _loc3_; _loc3_ = _loc3_ + 1; } this.volumePumped = 0; this.enteringLabourPool1 = this.pumpsHolder.enteringLabourPool1; this.goingToPump = this.pumpsHolder.goingToPump; this.leavingGame1 = this.pumpsHolder.leavingGame1; this.leavingGame2 = this.pumpsHolder.leavingGame2; this.labourPoolQueuePath = this.pumpsHolder.labourPoolQueuePath; this.pumps = [this.pumpsHolder.pump1,this.pumpsHolder.pump2,this.pumpsHolder.pump3,this.pumpsHolder.pump4,this.pumpsHolder.pump5,this.pumpsHolder.pump6,this.pumpsHolder.pump7,this.pumpsHolder.pump8,this.pumpsHolder.pump9,this.pumpsHolder.pump10]; this.pumpPaths = [this.pumpsHolder.goToPump1,this.pumpsHolder.goToPump2,this.pumpsHolder.goToPump3,this.pumpsHolder.goToPump4,this.pumpsHolder.goToPump5,this.pumpsHolder.goToPump6,this.pumpsHolder.goToPump7,this.pumpsHolder.goToPump8,this.pumpsHolder.goToPump9,this.pumpsHolder.goToPump10]; this.pumpQueues = [this.pumpsHolder.goToPump1,this.pumpsHolder.goToPump2,this.pumpsHolder.goToPump3,this.pumpsHolder.goToPump4,this.pumpsHolder.goToPump5,this.pumpsHolder.goToPump6,this.pumpsHolder.goToPump7,this.pumpsHolder.goToPump8,this.pumpsHolder.goToPump9,this.pumpsHolder.goToPump10]; this.pumpExits = [this.pumpsHolder.leavePump1,this.pumpsHolder.leavePump2,this.pumpsHolder.leavePump3,this.pumpsHolder.leavePump4,this.pumpsHolder.leavePump5,this.pumpsHolder.leavePump6,this.pumpsHolder.leavePump7,this.pumpsHolder.leavePump8,this.pumpsHolder.leavePump9,this.pumpsHolder.leavePump10]; this.enteringLabourPool1.init(this); this.goingToPump.init(this); this.leavingGame1.init(this); this.leavingGame2.init(this); this.labourPoolQueuePath.init(this); this.labourPool = new Queue(this.labourPoolQueuePath); _loc3_ = 0; while(_loc3_ < this.pumps.length) { this["pump" + (_loc3_ + 1)] = this.pumps[_loc3_]; this.pumpPaths[_loc3_].init(this); this.pumpQueues[_loc3_] = new Queue(this.pumpPaths[_loc3_]); this.pumps[_loc3_].init(this,this.pumpQueues[_loc3_],this.pumpExits[_loc3_]); _loc3_ = _loc3_ + 1; } this.f = 0; Key.addListener(this); this.timeRemaining = Engine.LVL_TIMES[0] * Engine.FPS; this.onEnterFrame = this.gameLoop; _root.kvEvent(Engine.MC_GAME_STARTED); } function gameLoop() { if(!this.paused) { var _loc2_ = undefined; this.f = this.f + 1; this.timeRemaining = this.timeRemaining - 1; this.perfCont.onEnterFrame(); if(this.timeRemaining <= 0) { this.gameOver(); } else { if(this.f % Math.round(this.newKidFrequency * Engine.FPS) == 1) { if(this.labourPool.length < Engine.MAX_LABOUR_POOL_SIZE) { this.addKid(); } } if(this.f == Engine.SHOW_FIRST_TIP_AT) { this.hud.tips.addMessage(Engine.TIPS[0]); this.hud.tips.addMessage(Engine.TIPS[1]); this.hud.tips.addMessage(Engine.TIPS[2]); } if(this.timeRemaining == Engine.SHOW_LOW_TIME_AT) { this.hud.tips.addMessage(Engine.TIP_LOW_TIME); } var _loc3_ = 0; _loc2_ = 0; while(_loc2_ < this.pumps.length) { _loc3_ += this.pumps[_loc2_].update(this.f); _loc2_ = _loc2_ + 1; } _loc2_ = 0; while(_loc2_ < this.allKids.length) { this.allKids[_loc2_].update(this.f); _loc2_ = _loc2_ + 1; } this.volumePumped += _loc3_; if(this.volumePumped >= Engine.LVL_TARGS[this.lvl]) { this.levelComplete(); } else { this.hud.update(this.volumePumped,Engine.LVL_TARGS[this.lvl],this.alreadyPumped,_loc3_,this.happyKids,this.unhappyKids,this.labourPool.length,this.timeRemaining); } } } } function levelComplete() { this.lvl = this.lvl + 1; if(this.lvl < Engine.NUM_LVLS) { this.volumePumped = 0; this.timeRemaining += Engine.LVL_TIMES[this.lvl] * Engine.FPS; this.newKidFrequency -= Engine.NEW_KID_FREQUENCY_INCREASE; this.hud.tips.addMessage(Engine.LEVEL_START_TIPS[this.lvl - 1]); this.play(); } else { this.gameComplete(); } } function gameComplete() { delete this.onEnterFrame; this.messages.inner.message_txt.text = "Well Done!"; this.messages.gotoAndPlay("show"); this.messages.endOfMessage = Delegate.create(this,this.doGameComplete); _root.kvEvent(Engine.MC_GAME_COMPLETE); } function doGameComplete() { _global.root.menu_mc.setNextPage("endGame"); _global.root.totalPumped = this.volumePumped; _global.root.levelReached = this.lvl; _global.root.timeLeft = this.timeRemaining / Engine.FPS; _global.root.completed = true; _root._quality = "HIGH"; } function gameOver() { delete this.onEnterFrame; this.messages.inner.message_txt.text = "Time\'s up!"; this.messages.gotoAndPlay("show"); this.messages.endOfMessage = Delegate.create(this,this.doGameOver); _root.kvEvent(Engine.MC_TIMEUP_EVENTS[this.lvl]); } function doGameOver() { _global.root.menu_mc.setNextPage("endGame"); _global.root.totalPumped = this.volumePumped; _global.root.levelReached = this.lvl; _global.root.timeLeft = 0; _global.root.completed = false; _root._quality = "HIGH"; } function addKid() { this.allKids.push(new Kid(this)); } function tiredTip() { if(!this.shownTiredTip) { this.shownTiredTip = true; this.hud.tips.addMessage(Engine.TIPS[3]); } } function exhaustedTip() { if(!this.shownExhaustedTip) { this.shownExhaustedTip = true; this.hud.tips.addMessage(Engine.TIPS[4]); } } function onKeyDown() { var _loc2_ = Key.getCode(); if(_loc2_ == 80 || _loc2_ == 19) { this.paused = !this.paused; } } function onUnload() { trace("die!"); Key.removeListener(this); } function get numberOfKids() { return this.allKids.length; } function get happyKids() { var _loc3_ = 0; var _loc2_ = 0; while(_loc2_ < this.allKids.length) { if(!this.allKids[_loc2_].leaving && this.allKids[_loc2_].happy) { _loc3_ = _loc3_ + 1; } _loc2_ = _loc2_ + 1; } return _loc3_; } function get unhappyKids() { var _loc3_ = 0; var _loc2_ = 0; while(_loc2_ < this.allKids.length) { if(!this.allKids[_loc2_].leaving && !this.allKids[_loc2_].happy) { _loc3_ = _loc3_ + 1; } _loc2_ = _loc2_ + 1; } return _loc3_; } function get alreadyPumped() { var _loc3_ = 0; var _loc2_ = 0; while(_loc2_ < this.lvl) { _loc3_ += Engine.LVL_TARGS[_loc2_]; _loc2_ = _loc2_ + 1; } return _loc3_; } function set paused(b) { if(b != this._paused) { if(!b) { } this.blocker._visible = b; this._paused = b; } } function get paused() { return this._paused; } }